package com.wcar.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.wcar.common.entity.Role;
import com.wcar.common.vo.Result;
import com.wcar.user.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: four-wcar-idea
 * @description:
 * @author: 吴朝阳
 * @create: 2024-05-28 09:34
 **/
@RestController
@RequestMapping("/user")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @PostMapping("/getRole/{currentPage}/{pageSize}")
    public Result<IPage<Role>> getUser(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody Role role) {
        System.out.println(role);
        return roleService.getRole(currentPage, pageSize,role);
    }
    @PostMapping("/addRole")
    public Result<Role> addRole(@RequestParam String username,@RequestBody Role role){
        System.out.println(username);
        return roleService.addRole(username,role);
    }
    @DeleteMapping("/deleteRole")
    public Result<Role> deleteRole(Integer roleId){
        return roleService.deleteRole(roleId);
    }
    @PostMapping("updateRole")
    public Result<Role> updateRole(@RequestParam String username,@RequestBody Role role){
        return roleService.updateRole(username,role);
    }
    @PostMapping("/selectRole")
    public Result<List<Role>> selectRole(@RequestParam Integer id){
        return roleService.selectRole(id);
    }
    @PostMapping("/role/updateRole")
    public Result<Role> updateRole(@RequestParam Integer userId,@RequestBody List<Integer> role){
        return roleService.updateRoles(userId,role);
    }
    @GetMapping("/selectRoleMenus")
    public Result<List<Integer>> selectRoleMenus(@RequestParam Integer roleId){
        return roleService.selectRoleMenus(roleId);
    }

    @PostMapping("/addMenuByRole")
    public Result<Integer> update(@RequestParam Integer roleId, @RequestBody ArrayList<Integer> menuIds){
        return roleService.update(roleId,menuIds);
    }
}
